<div style="padding: 30px;" class="layui-form seller-alone-form"> <!-- 提示：如果你不想用form，你可以换成div等任何一个普通元素 -->

    <div class="layui-form-item">
        <label class="layui-form-label"><i class="required-color">*</i>规则名称：</label>
        <div class="layui-input-inline seller-inline-5">
            <input type="text" name="name" required lay-verify="required" placeholder="请输入规则名称" autocomplete="off" class="layui-input">
        </div>
    </div>
 
    <div class="layui-form-item">
        <label class="layui-form-label"><i class="required-color">*</i>充值金额：</label>
        <div class="layui-input-inline seller-inline-5">
            <input type="text" name="money" required lay-verify="required" placeholder="请输入充值金额" autocomplete="off" class="layui-input">
        </div>
    </div>
    
    <div class="layui-form-item">
        <label class="layui-form-label"><i class="required-color">*</i>赠送金额：</label>
        <div class="layui-input-inline seller-inline-5">
            <input type="text" name="gift" required lay-verify="required" placeholder="请输入赠送金额" autocomplete="off" class="layui-input">
        </div>
    </div>
    
    <div class="layui-form-item">
        <label class="layui-form-label"><i class="required-color">*</i>规则说明：</label>
        <div class="layui-input-inline seller-inline-5">
            <input type="text" name="desc" required lay-verify="required" placeholder="请输入规则说明" autocomplete="off" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">失效时间：</label>
        <div class="layui-input-inline">
            <input type="text" name="expires_in" id="expires_in" placeholder="请选择失效时间" autocomplete="off" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label"><i class="required-color">*</i>规则排序：</label>
        <div class="layui-input-inline seller-inline-2">
            <input type="text" name="sort" required lay-verify="required" value="100" placeholder="数值越小越靠前" autocomplete="off" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item" style="margin: 20px;">
        <label class="layui-form-label">是否发布：</label>
        <div class="layui-input-block">
            <input type="radio" name="is_pub" value="1" title="立即发布">
            <input type="radio" name="is_pub" value="2" title="暂不发布" checked>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">注意：</label>
    
        <div class="layui-input-block" style="font-size:14px; padding-top:10px;">
            <p>赠送金额：填写赠送金额，请注意用户退款风险！</p>
            <p>失效日期：规则自动失效日期为设定日期的24点，微信小程序过期自动屏蔽，防止用户误购！</p>
            <p>失效日期：不填写则为永久有效！</p>
            <p>规则生效：发布后，规则立即生效！</p>
        </div>
    </div> 

    <div class="layui-form-item" style="padding-top:20px;">
        <div class="layui-input-block">
            {:zlserverToken()}
            <button id="recharge_add_save" type="button" class="layui-btn" lay-submit lay-filter="save">保存</button>
        </div>
    </div>
    <!-- 更多表单结构排版请移步文档左侧【页面元素-表单】一项阅览 -->
</div>
<script>
    layui.use(['form','table', 'laydate'], function(){
        var $ = layui.$,form = layui.form,table = layui.table, laydate = layui.laydate;
        //监听提交
        form.render();
        
        laydate.render({
            elem: '#expires_in'
        });
     
        //保存规则
        form.on('submit(save)', function(data){
            formData = data.field;
            if(!formData){
                layer.msg('请先完善数据', {time: 1300});
                return false;
            }
 
            var reg = /(^([-]?)[1-9]([0-9]+)?(\.[0-9]{1,2})?$)|(^([-]?)(0){1}$)|(^([-]?)[0-9]\.[0-9]([0-9])?$)/; 
            if (!reg.test(formData.money)) {
                layer.msg('请输入正确的充值金额');
                return;
            }
            if (!reg.test(formData.gift)) {
                layer.msg('请输入正确的赠送金额');
                return;
            }

            $("#recharge_add_save").addClass("layui-btn-disabled");
            $('#recharge_add_save').attr("disabled", true);

            $.ajax({
                type: 'post',
                url: '{:url("Recharge/add")}',
                data: formData,
                dataType: 'json',
                success: function (e) { 
                    if(e.status === true){ 
                        layer.open({
                            type: 1
                            ,offset: 'auto'
                            ,id: 'layerDemoAuto'
                            ,content: '<div style="padding: 20px 100px;">'+ e.msg +'</div>'
                            ,btn: '关闭'
                            ,btnAlign: 'c' //按钮居中
                            ,shade: 0.3 //显示遮罩
                            ,yes: function(){
                                parent.layui.admin.events.changeTabAndRefresh('/manage/recharge/index.html');
                            },close: function() {
                                console.log('close');
                            },end: function () {
                                parent.layui.admin.events.changeTabAndRefresh('/manage/recharge/index.html');
                            }
                        });
                    }else{
                        $("#recharge_add_save").removeClass("layui-btn-disabled");
                        $('#recharge_add_save').removeAttr("disabled");

                        layer.msg(e.msg, {time: 1300});
                    }
                }
            });
            
            return false;
        });
    });

</script>